//
//  HMStatusToolBar.swift
//  01-SinaWeibo
//
//  Created by 周英培 on 16/5/25.
//  Copyright © 2016年 周英培. All rights reserved.
//

import UIKit

import SnapKit

class HMStatusToolBar: UIView {
    
    //添加视图模型属性
    var statusViewModel : HMStatusViewModel? {
    
        didSet {
        
           repostsBtn.setTitle(statusViewModel?.reportsText, forState: .Normal)
            commentsBtn.setTitle(statusViewModel?.commentsText, forState: .Normal)
            ohYeahBtn.setTitle(statusViewModel?.attitudesText, forState: .Normal)
        
        }
    
    }
    

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setUpUI()
        //设置北京颜色
//        backgroundColor = UIColor(white: 0.9, alpha: 1)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK:懒加载
    //转发
    private lazy var repostsBtn : UIButton = UIButton()
    
    //评论
    private lazy var commentsBtn : UIButton = UIButton()
    
    //点赞
    private lazy var ohYeahBtn : UIButton = UIButton()
    
    private func addChildBtn(btn:UIButton,title:String,imageName:String) {
    
        btn.setTitle(title, forState: .Normal)
        btn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        btn.titleLabel?.font = UIFont .systemFontOfSize(10)
        btn.setImage(UIImage(named: imageName), forState: .Normal)
        btn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: .Normal)
        btn.sizeToFit()
        addSubview(btn)
    
    }
    
    private func lineView() -> UIView {
    
        let v = UIView()
        
        v.backgroundColor = UIColor.redColor()
        
        return v
     
    }
    
    //MARK:设置子视图，给子视图设置约束
    private func setUpUI() {
        addChildBtn(repostsBtn, title: "转发", imageName: "timeline_icon_retweet")
        addChildBtn(commentsBtn, title: "评论", imageName: "timeline_icon_comment")
        addChildBtn(ohYeahBtn, title: "点赞", imageName: "timeline_icon_like")
        
        //给转发按钮设置约束
        repostsBtn.snp_makeConstraints { (make) in
            make.top.left.bottom.equalTo(self)
            
        }
        
        //给评论按钮设置约束
        commentsBtn.snp_makeConstraints { (make) in
            make.left.equalTo(repostsBtn.snp_right)
            make.top.bottom.equalTo(repostsBtn)
            make.width.equalTo(repostsBtn.snp_width)
        }
        
        //给点赞按钮设置约束
        ohYeahBtn.snp_makeConstraints { (make) in
            make.left.equalTo(commentsBtn.snp_right)
            make.top.bottom.equalTo(commentsBtn)
            make.right.equalTo(self)
            make.width.equalTo(repostsBtn.snp_width)
        }
        
        let line1 = lineView()
        let line2 = lineView()
        let width = 1 / UIScreen.mainScreen().scale
        
        addSubview(line1)
        addSubview(line2)
        
        line1.snp_makeConstraints { (make) in
            make.left.equalTo(repostsBtn.snp_right)
            make.width.equalTo(width)
            make.centerY.equalTo(self)
            make.height.equalTo(self).multipliedBy(0.5)
        }
        
        line2.snp_makeConstraints { (make) in
            make.left.equalTo(commentsBtn.snp_right)
            make.width.equalTo(width)
            make.height.equalTo(self).multipliedBy(0.5)
            make.centerY.equalTo(self)
        }
        
        
    
    
    }
}
